<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>API列表</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/admin/css/pear-tree/dtree.css}"/>
    <link rel="stylesheet" th:href="@{/admin/css/pear-tree/font/dtreefont.css}"/>
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <style>
        .dtree-nav-div cite {
            font-family: 'Roboto', sans-serif;
            font-size: 15px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div id="test1"></div>

    </div>
</div>

<input type="hidden" th:value="${clientId}" id="clientId">
<input type="hidden" th:value="${ap}" id="ap">

<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/admin/js/jquery.js}"></script>
<script>
    var treeData = null;
    var clientId = $("#clientId").val();
    var ap = $("#ap").val();
    var requestURL = "/restdoc/document/serviceClient/" + clientId + "/apiList?ap=" + ap;

    $.ajax({
        type: 'GET',
        contentType: 'application/json;charset=utf-8',
        url: requestURL,
        async: false,
        success: function (data) {
            if (data['code'] === "200") {
                treeData = data['data'];
            } else {
                layer.msg(data['message']);
            }
        },
        error: function () {
            layer.msg("网络异常")
        }
    });

    var layuiTree = null;

    layui.use(['tree','dtree'], function () {
        var tree = layui.tree;
        layuiTree = tree;
        var dtree = layui.dtree;

        var inst1 = tree.render({
            elem: '#test1',
            id: "apiListTree",
            data: treeData,
            showCheckbox: true
        });
    });

    function getCheckApi() {
        var apiList = layuiTree.getChecked('apiListTree');
        var res = [];
        for (var i = 0; i < apiList.length; i++) {
            var api = apiList[i];
            if (api.children != null && api.children.length > 0) {
                for (var j = 0; j < api.children.length; j++) {
                    var doc = api.children[j];
                    res.push(doc.id);
                }
            }
        }
        return res;
    }

</script>
</body>
</html>